<?php

namespace App\Models\V1;

use Illuminate\Database\Eloquent\Model;
use App\Scopes\V1\ValidDataScope;

class Submenus extends Model
{
    protected $table = 'submenus';

    /**
     * 模型启动函数
     */
    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new ValidDataScope);
    }

    /**
     * 可被批量赋值字段（白名单）
     *
     * @var array
     */
    protected $fillable = [
        'code','name','parent_code','menu_code','iconfont','show_level','url',
    ];

    /**
     * 限制数组或JSON输出时，隐藏字段
     *
     * @var array
     */
    protected $hidden = [
        'id','deleted_at',
    ];

    /**
     * 获取子菜单对应的菜单信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function menu()
    {
        return $this->belongsTo(Menus::class,'menu_code','code');
    }
}
